﻿using System;
namespace Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="aadress3", Namespace="http://producers.taitis.xtee.riik.ee/producer/taitis", Target=typeof(Aadress3))]
    public class Aadress3Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAadress3 clazz;
        
        public Aadress3Serializer(IAadress3 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ehak");
            if (clazz.Ehak!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Ehak))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Ehak");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("tanav");
            if (clazz.Tanav!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tanav))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tanav");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("aadress");
            if (clazz.Aadress!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Aadress))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Aadress");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("aadresskokku");
            if (clazz.Aadresskokku!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Aadresskokku))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Aadresskokku");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("postiindeks");
            if (clazz.Postiindeks!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Postiindeks))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Postiindeks");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("riik");
            if (clazz.Riik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Riik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Riik");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "ehak")) {
                goto ehak;
            }
            else {
                if ((Reader.LocalName == "tanav")) {
                    goto tanav;
                }
                else {
                    if ((Reader.LocalName == "aadress")) {
                        goto aadress;
                    }
                    else {
                        if ((Reader.LocalName == "aadresskokku")) {
                            goto aadresskokku;
                        }
                        else {
                            if ((Reader.LocalName == "postiindeks")) {
                                goto postiindeks;
                            }
                            else {
                                if ((Reader.LocalName == "riik")) {
                                    goto riik;
                                }
                                else {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        ehak:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadress3>ehak");
            }
            clazz.Ehak = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ehak")).Value;
            goto START;
        tanav:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadress3>tanav");
            }
            clazz.Tanav = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tanav")).Value;
            goto START;
        aadress:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadress3>aadress");
            }
            clazz.Aadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aadress")).Value;
            goto START;
        aadresskokku:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadress3>aadresskokku");
            }
            clazz.Aadresskokku = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aadresskokku")).Value;
            goto START;
        postiindeks:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadress3>postiindeks");
            }
            clazz.Postiindeks = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("postiindeks")).Value;
            goto START;
        riik:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadress3>riik");
            }
            clazz.Riik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("riik")).Value;
            goto START;
        }
    }
}
